package com.example.wan1.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.wan1.R;
import com.example.wan1.model.NaviBean;
import com.example.wan1.view.web.JumpTool;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import mao.com.flexibleflowlayout.TagAdapter;
import mao.com.flexibleflowlayout.TagFlowLayout;

/***
 * 创建时间：2020/7/10 20:39
 * 创建人：10850
 * 功能描述：导航适配器
 */
public class NaviAdapter extends BaseQuickAdapter<NaviBean, BaseViewHolder> {
    public NaviAdapter(int layoutResId, @Nullable List<NaviBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, NaviBean item) {
        helper.setText(R.id.nav_item_tv, item.getName());

        TagFlowLayout view = helper.getView(R.id.nav_item_ff);
        view.setAdapter(new TagAdapter() {
            @Override
            public int getItemCount() {
                return item.getArticles().size();
            }

            @Override
            public View createView(LayoutInflater inflater, ViewGroup parent, int position) {
                return inflater.inflate(R.layout.knowledge_flow_text_layout, parent, false);
            }

            @Override
            public void bindView(View view, int position) {
                TextView textView = view.findViewById(R.id.knowledge_tag_text);
                textView.setText(item.getArticles().get(position).getTitle());
            }

            @Override
            public void onTagItemViewClick(View v, int position) {
                super.onTagItemViewClick(v, position);
                /*List<ArticleBean> articles = getData().get(position).getArticles();
                for (int i = 0; i < articles.size(); i++) {
                    Log.i("zxd", "onTagItemViewClick: " + articles.get(i).toString());
                }*/
                JumpTool.goWeb(mContext, item.getArticles().get(position).getTitle(),
                        item.getArticles().get(position).getLink());
            }
        });
    }
}
